let Api = require('../../utils/api.js');
let wxRequest = require('../../utils/wxRequest.js');

Page({
  data: {
    token: ''
  },
  onLoad: function () {
    let user = wx.getStorageSync('user')
    if (!user) {
      wx.reLaunch({
        url: '../login/login',
      })
    } else {
      this.setData({
        token: user.code
      })
      this.doInit()
    }
  },
  totaltap: function () {
    wx.navigateTo({
      url: '../total/index',
    })
  },
  financetap: function () {
    wx.navigateTo({
      url: '../finance/finance',
    })
  },
  settingtap: function () {
    wx.navigateTo({
      url: '../my/my',
    })
  },
  hosptap: function () {
    wx.navigateTo({
      url: '../hosp/index',
    })
  },
  doInit: function () {
    let self = this
    wx.showLoading({
      title: '正在加载...',
    })
    wxRequest.getRequest(Api.agInfo(self.data.token), null).then(res => {
      if (res.data) {
        let data = res.data
        wx.setStorageSync('idata', data)
      }
    }).finally(fina => {
      wx.hideLoading()
    })
  }
})